package cn.itheima.web;

import cn.itheima.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author: cuisensen
 * data: 2018/7/2.
 * time: 20:37.
 */
@WebServlet("/relay")
public class RelayServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String includePage=(String)request.getParameter("includePage");
        HttpSession session = request.getSession();
        User user= (User) session.getAttribute("user");
        if(includePage.equals("sectionManager.jsp")){
            if (user.getRoot()==1){
                request.getSession().setAttribute("includePage",includePage);
            }
        }else{
            request.getSession().setAttribute("includePage",includePage);
        }
        response.sendRedirect(request.getContextPath()+"/index.jsp");
    }
}
